/* AIOD Analysis */ 
/* Lapinski et al., "What Do Citizens Want from their Member of Congress?", PRQ */ 
/* April 2016 */ 

clear 
use "prq_replication_data.dta"
svyset [pweight = nat_wgt] /* correct for over-samples */ 

/* Background Variables */ 
gen pid = . 
replace pid = 1 if f1 == 2 & f2 == 1 
replace pid = 2 if f1 == 2 & f2 == 2 
replace pid = 3 if f1 > 2 & f3 == 2 
replace pid = 4 if f1 > 2 & f3 > 2  
replace pid = 5 if f1 > 2 & f3 == 1 
replace pid = 6 if f1 == 1 & f2 == 2 
replace pid = 7 if f1 == 1 & f2 == 1   

gen pid3_lean = .  
replace pid3_lean = 1 if pid < 4 
replace pid3_lean = 0 if pid == 4 
replace pid3_lean = 2 if pid > 4 

gen sp = 0 
replace sp = 1 if pid == 1 | pid == 7 

gen tp = 0 
replace tp = 1 if f5 == 1 

gen female = 0 
replace female = 1 if z1 == 2 

gen black = 0 
replace black = 1 if z11_1 == 2   

/* race: 1 = white, 2 = aa, 3 = asian, 0 = other */  
gen race = 0 
replace race = 1 if z11_1 == 1 
replace race = 2 if z11_1 == 2 
replace race = 3 if z11_1 == 3 

gen latino = 0 
replace latino = 1 if z9 == 1 

gen libcon = . 
replace libcon = (-1*f4) + 6 if f4 < 6 

/* 3 pt libcon: lib (2), mod (1), cons (3) */ 
gen libcon3 = . 
replace libcon3 = 2 if libcon < 3 
replace libcon3 = 1 if libcon == 3 
replace libcon3 = 3 if libcon > 3 

gen sorted = 0 
replace sorted = 1 if pid3_lean == 1 & libcon3 == 2 
replace sorted = 1 if pid3_lean == 2 & libcon3 == 3 

gen educ = . 
replace educ = z25 if z25 < 10 

gen baormore = 0  
replace baormore = 1 if educ > 6  
replace baormore = . if z25 > 9  

gen income = . 
replace income = z26ax if z26ax < 7 

gen inc_thirds = . 
replace inc_thirds = 1 if income < 3 
replace inc_thirds = 2 if income == 3 
replace inc_thirds = 3 if income > 3 & income < 7 

gen age = . 
replace age = z2 if z2 < 98 

/* Age in bins */ 
gen age_bin = . 
replace age_bin = 1 if age < 30  /* ages 18-29 */ 
replace age_bin = 2 if age > 29 & age < 45 /* ages 30-44 */ 
replace age_bin = 3 if age > 44 & age < 65 /* ages 45-64 */ 
replace age_bin = 4 if age > 64 /* ages 65+ */ 

gen elect_interest = w1 if w1 < 11 


/* think you're rep by own party */ 
gen think_party_match = 0 
replace think_party_match = 1 if pid3_lean == 1 & d1 == 1 
replace think_party_match = 1 if pid3_lean == 2 & d1 == 2   

/* Create week fixed effects */ 
tostring thedate, replace   
gen survey_date = date(thedate,"YMD") 
gen int week  = wofd(survey_date) /* this gives Stata's week, which isn't exactly Su-Su, but close enough */ 


/* Table 1 (AIOD Analysis): How Much Does X Matter to Your Vote? */ 
gen service_matter = (-1*e21)+5 if e21 < 5 
gen issues_matter = (-1*e23)+5 if e23 < 5 
gen control_matter = (-1*e24)+5 if e24 < 5 
gen projects_matter = (-1*e24a)+5 if e24a < 5  

svy: tabulate issues_matter 
svy: tabulate service_matter 
svy: tabulate projects_matter 
svy: tabulate control_matter 


/* Table 2: Which Party Would Do X Better? */ 
/* Which Party Would Do It Better? */ 
gen own_project = 0 
replace own_project = 1 if e8 == 1 & pid < 4 
replace own_project = 1 if e8 == 2 & pid > 4 
replace own_project = . if e8 == . 

gen own_problem = 0 
replace own_problem = 1 if e9 == 1 & pid < 4 
replace own_problem = 1 if e9 == 2 & pid > 4 
replace own_problem = . if e9 == . 

gen own_special = 0 
replace own_special = 1 if e10 == 1 & pid < 4 
replace own_special = 1 if e10 == 2 & pid > 4 
replace own_special = . if e10 == . 

gen nd_project = 0 
replace nd_project = 1 if e8 == 3 | e8 == 8 
replace nd_project = . if e8 == . 

gen nd_problem = 0 
replace nd_problem = 1 if e9 == 3 | e9 == 8 
replace nd_problem = . if e9 == .

gen nd_special = 0 
replace nd_special = 1 if e10 == 3 | e10 == 8 
replace nd_special = . if e10 == . 

gen nd_represent = 0 
replace nd_represent = 1 if e11 == 3 | e11 == 8 
replace nd_represent = . if e11 == .  

gen own_rep_better = 0 
replace own_rep_better = 1 if e11 == 1 & pid < 4 
replace own_rep_better = 1 if e11 == 2 & pid > 4 
replace own_rep_better = . if e11 == . 

/* 1: Same Party, -1: Opposite Party, 0: No Difference */ 
gen which_projects = . 
replace which_projects = 1 if own_project == 1 
replace which_projects = 0 if nd_project == 1 
replace which_projects = -1 if own_project == 0 & nd_project == 0 

gen which_problem = . 
replace which_problem = 1 if own_problem == 1 
replace which_problem = 0 if nd_problem == 1 
replace which_problem = -1 if own_problem == 0 & nd_problem == 0 

gen which_special = . 
replace which_special = 1 if own_special == 1 
replace which_special = 0 if nd_special == 1 
replace which_special = -1 if own_special == 0 & nd_special == 0 

gen which_represent = . 
replace which_represent = 1 if own_rep_better == 1 
replace which_represent = 0 if nd_represent == 1 
replace which_represent = -1 if own_rep_better == 0 & nd_project == 0 

gen other_projects = 0
replace other_projects = 1 if which_projects == -1 
replace other_projects = . if which_projects == . 

gen other_problem = 0
replace other_problem = 1 if which_problem == -1 
replace other_problem = . if which_problem == . 

gen which_belief = . 
replace which_belief = 1 if e12 == 1 & pid < 4 
replace which_belief = 1 if e12 == 2 & pid > 4 
replace which_belief = 0 if e12 == 3 
replace which_belief = -1 if e12 == 1 & pid > 4 
replace which_belief = -1 if e12 == 2 & pid < 4 

gen which_reelect = . 
replace which_reelect = 1 if e13 == 1 & pid < 4 
replace which_reelect = 1 if e13 == 2 & pid > 4 
replace which_reelect = 0 if e13 == 3 
replace which_reelect = -1 if e13 == 1 & pid > 4 
replace which_reelect = -1 if e13 == 2 & pid < 4  

svy: tabulate which_reelect 
svy: tabulate which_belief 
svy: tabulate which_projects 
svy: tabulate which_problem 
svy: tabulate which_special 
svy: tabulate which_represent  

/* Table 3: Analysis of Ranking Item */ 
/* What Issues Are Most Important: Issues, Service, Character, Partisanship? */ 
gen issues1 = 0 
replace issues1 = 4 if e35 == 3 
gen issues2 = 0 
replace issues2 = 3 if e35b == 3 
gen issues3 = 0 
replace issues3 = 2 if e35c == 3 
gen issues4 = 0 
replace issues4 = 1 if e35a == 3 
egen issue_import = rsum(issues1 issues2 issues3 issues4) 
replace issue_import = . if issue_import == 0 /* NA for those not asked */ 

gen service1 = 0 
replace service1 = 4 if e35 == 2 
gen service2 = 0 
replace service2 = 3 if e35b == 2 
gen service3 = 0 
replace service3 = 2 if e35c == 2 
gen service4 = 0 
replace service4 = 1 if e35a == 2 
egen service_import = rsum(service1 service2 service3 service4) 
replace service_import = . if service_import == 0 /* NA for those not asked */ 

gen char1 = 0 
replace char1 = 4 if e35 == 1 
gen char2 = 0 
replace char2 = 3 if e35b == 1 
gen char3 = 0 
replace char3 = 2 if e35c == 1 
gen char4 = 0 
replace char4 = 1 if e35a == 1 
egen char_import = rsum(char1 char2 char3 char4) 
replace char_import = . if char_import == 0 /* NA for those not asked */ 

gen party1 = 0 
replace party1 = 4 if e35 == 4 
gen party2 = 0 
replace party2 = 3 if e35b == 4 
gen party3 = 0 
replace party3 = 2 if e35c == 4 
gen party4 = 0 
replace party4 = 1 if e35a == 4 
egen party_import = rsum(party1 party2 party3 party4) 
replace party_import = . if party_import == 0 /* NA for those not asked */  

svy: mean issue_import 
svy: mean service_import 
svy: mean party_import 
svy: mean char_import 

/* Table 3, column 1 */ 
svy: reg service_import sorted tp female i.race latino baormore i.inc_thirds i.age_bin elect_interest i.week

/* Table 3, column 2 */ 
svy: reg issue_import sorted tp female i.race latino baormore i.inc_thirds i.age_bin elect_interest i.week 

/* Table 3, column 3 */ 
gen issue_over_service = 0 
replace issue_over_service = 1 if issue_import > service_import 
replace issue_over_service = . if issue_import== . | service_import == . 

svy: logit issue_over_service sorted tp female i.race latino baormore i.inc_thirds i.age_bin elect_interest i.week 
margins, dydx(sorted)
margins, dydx(baormore) 
/* effects are sorted: 13%, ba: 6% */ 

/* Table 3, columns 4-6 */ 
svy: reg service_import sorted##baormore tp female i.race latino baormore i.inc_thirds i.age_bin elect_interest i.week
svy: reg issue_import sorted##baormore tp female i.race latino baormore i.inc_thirds i.age_bin elect_interest i.week 
svy: logit issue_over_service sorted##baormore tp female i.race latino baormore i.inc_thirds i.age_bin elect_interest i.week 
margins sorted#baormore 
margins r.sorted, over(baormore) 

/* Table 4: Vote Choice Analysis */ 
gen vote_party = .  /* house vote */ 
replace vote_party = 1 if c15 == 1 & pid > 4  
replace vote_party = 1 if c15 == 2 & pid < 4  
replace vote_party = 0 if c15 == 2 & pid > 4 
replace vote_party = 0 if c15 == 1 & pid < 4 

svy: logit vote_party think_party_match sp issue_over_service i.week 
